﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using Microsoft.Practices.Prism.Events;
using ModulesInfrastructure.ViewModels;
using ServerConnection.ShopServiceReference;
using ServerConnection;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Unity;
using EventInfrastructure;
using Microsoft.Practices.Prism.Regions;
using ModuleProductDetail.Views;
using ShellInfrastructure;

namespace ModuleProductDetail.ViewModels
{
    public class ProductDetailViewModel : SharedViewModel, IProductDetailViewModel
    {

        #region private filds

        private IEventAggregator m_eventAggregator;

        #endregion

        #region public proprties

        [Dependency]
        public IRegionManager RegionManager { get; set; }
        public List<ProductFull> ShowProduct { get; private set; }

        #endregion

        #region constructor

        public ProductDetailViewModel(IEventAggregator eventAggregator)
        {
            this.m_eventAggregator = eventAggregator;
            eventAggregator.GetEvent<ProductSelectEvent>().Subscribe(onDrawRegionEvent);
        }

        #endregion

        #region private functions

        private void onDrawRegionEvent(long id)
        {
            RegionManager = ServiceLocator.Current.GetInstance<IRegionManager>();
            IRegion region = RegionManager.Regions[RegionNames.RightRegionName];
            region.Activate(ServiceLocator.Current.GetInstance<IProductDetailView>());
            this.ShowProduct = new List<ProductFull>();
            this.ShowProduct.Add(Service.Instance.GetProductFullById(id,"eng"));
            RaisePropertyChanged(() => this.ShowProduct);
        }

        #endregion

    }
}
